package com.das.mechanic_base.utils;

import com.das.mechanic_base.bean.alone.NewServiceHeaderBean;
import com.das.mechanic_base.bean.greendao.AloneServiceListBean;

import java.util.Iterator;
import java.util.List;

public class X3AloneServiceSearchUtils {

    public static AloneServiceListBean searchAloneServiceBean(List<AloneServiceListBean> cacheList,String serviceSn) {
        AloneServiceListBean listBean = null;
        if (X3StringUtils.isListEmpty(cacheList)) {
            return null;
        }
        for (int i = 0; i < cacheList.size(); i++) {
            AloneServiceListBean listBean1 = cacheList.get(i);
            if (listBean1 == null) {
                continue;
            }
            if (serviceSn.equals(listBean1.getTouchServiceSn())) {
                listBean = listBean1;
                break;
            }
        }

        return listBean;
    }

    public static List<AloneServiceListBean> replaceAloneServiceBean(List<AloneServiceListBean> cacheList,String serviceSn,
                                                                     AloneServiceListBean replaceBean) {
        List<AloneServiceListBean> newCacheList = cacheList;
        if (X3StringUtils.isListEmpty(cacheList)) {
            return newCacheList;
        }
        for (int i = 0; i < newCacheList.size(); i++) {
            AloneServiceListBean aloneServiceListBean = newCacheList.get(i);
            if (aloneServiceListBean.getTouchServiceSn().equals(serviceSn)) {
                newCacheList.remove(i);
                newCacheList.add(i,replaceBean);
                break;
            }
        }
        return newCacheList;
    }

    public static List<AloneServiceListBean> deleteAloneServiceBean(List<AloneServiceListBean> cacheList,String serviceSn) {
        List<AloneServiceListBean> newCacheList = cacheList;
        if (X3StringUtils.isListEmpty(cacheList)) {
            return newCacheList;
        }
        Iterator<AloneServiceListBean> iterator = newCacheList.iterator();
        while (iterator.hasNext()) {
            AloneServiceListBean next = iterator.next();
            if (next.getTouchServiceSn().equals(serviceSn)) {
                iterator.remove();
            }
        }
        return newCacheList;
    }

    public static NewServiceHeaderBean.AlreadyInPlanListBean searchNewAloneServiceBean(List<NewServiceHeaderBean.AlreadyInPlanListBean> cacheList, String serviceSn) {
        NewServiceHeaderBean.AlreadyInPlanListBean listBean = null;
        if (X3StringUtils.isListEmpty(cacheList)) {
            return null;
        }
        for (int i = 0; i < cacheList.size(); i++) {

            NewServiceHeaderBean.AlreadyInPlanListBean alreadyInPlanListBean = cacheList.get(i);
            if (alreadyInPlanListBean == null) {
                continue;
            }
            if (serviceSn.equals(alreadyInPlanListBean.serviceBaseSn)) {
                listBean = alreadyInPlanListBean;
                break;
            }
        }

        return listBean;
    }

    public static List<NewServiceHeaderBean.AlreadyInPlanListBean> replaceNewAloneServiceBean(List<NewServiceHeaderBean.AlreadyInPlanListBean> cacheList,String serviceSn,
                                                                                              NewServiceHeaderBean.AlreadyInPlanListBean replaceBean) {
        List<NewServiceHeaderBean.AlreadyInPlanListBean> newCacheList = cacheList;
        if (X3StringUtils.isListEmpty(cacheList)) {
            return newCacheList;
        }
        for (int i = 0; i < newCacheList.size(); i++) {
            NewServiceHeaderBean.AlreadyInPlanListBean aloneServiceListBean = newCacheList.get(i);
            if (aloneServiceListBean.serviceBaseSn.equals(serviceSn)) {
                newCacheList.remove(i);
                newCacheList.add(i,replaceBean);
                break;
            }
        }
        return newCacheList;
    }

    public static List<NewServiceHeaderBean.AlreadyInPlanListBean> deleteNewAloneServiceBean(List<NewServiceHeaderBean.AlreadyInPlanListBean> cacheList,String serviceSn) {
        List<NewServiceHeaderBean.AlreadyInPlanListBean> newCacheList = cacheList;
        if (X3StringUtils.isListEmpty(cacheList)) {
            return newCacheList;
        }
        Iterator<NewServiceHeaderBean.AlreadyInPlanListBean> iterator = newCacheList.iterator();
        while (iterator.hasNext()) {
            NewServiceHeaderBean.AlreadyInPlanListBean next = iterator.next();
            if (next.serviceBaseSn.equals(serviceSn)) {
                iterator.remove();
            }
        }
        return newCacheList;
    }

}
